import React, { useEffect } from "react";
import { useSelector, useDispatch, connect } from "react-redux";
import { a } from "@/request/api";

import AsyncNumber from "@/store/reducer/number/action";
const View = (props: RootState) => {
  //通过useSelector导入store的数据
  // const num = useSelector((state: RootState) => state.number);
  //通过useDispatch()触发store中的事件
  const dispatch = useDispatch();
  //异步更新num的值
  const asyncUpdate = () => {
    dispatch(AsyncNumber.asyncAction.asyncAdd);
  };
  //同步更新num的值
  const update = () => {
    dispatch({ type: "add", val: 1 });
  };
  useEffect(() => {
    async function getData() {
      let b = await a();
      console.log(b.msg, "bb");
    }
    getData();
  });
  return (
    <div>
      <div>飞车页面</div>;{props.num}
      <br />
      <button onClick={asyncUpdate}>异步修改num</button>
      <button onClick={update}>同步修改num</button>
    </div>
  );
};
//通过connect导入store的数据
export default connect((state: any) => state.number)(View);
